package tests;

import junit.framework.*;
import java.util.ArrayList;
import java.util.Date;
import java.text.*;

import org.junit.Before;
import org.junit.Test;

import Model.DeleteTaskCommand;
import Model.Task;

/**
 * JUnit test case for DeleteTaskCommandTest
 */

public class DeleteTaskCommandTest extends TestCase {
	//declare reusable objects to be used across multiple tests
    DeleteTaskCommand t1;
    ArrayList<Task> arrList=null;
	Date utilDate = new Date();
	Task newtask;
	
	public DeleteTaskCommandTest(String name) {
		super(name);
	}
	
	@Before
	protected void setUp() {
		//define reusable objects to be used across multiple tests
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
					    
			try { 

			 utilDate = df.parse("15/11/2011");
		     arrList = new ArrayList<Task>();
		     newtask = new Task("Task 1",utilDate,"Type 1");
		     arrList.add(newtask);
			 
			 t1 = new DeleteTaskCommand(arrList);
			 
					} 
					
					catch (ParseException e) {
						e.printStackTrace();
					}
		}


	@Test
	public void testDeleteTaskCommandConstructor() {
		
		DeleteTaskCommand var0 = new DeleteTaskCommand(arrList);
		assertNotNull("Object is created",var0);
	}
	
	@Test
	public void testExecute() {
		
		assertEquals(arrList.size(),1);
		t1.execute("Task 1");
		assertEquals(arrList.size(),0);
		
	}
	
	@Test
	public void testUndo() {

		assertEquals(arrList.size(),1);
		t1.execute("Task 1");
		assertEquals(arrList.size(),0);
		t1.undo();
		assertEquals(arrList.size(),1);
		assertEquals(arrList.get(0).getName(),"Task 1");
		assertEquals(arrList.get(0).getType(),"Type 1");
		assertEquals(arrList.get(0).getDueDate(),utilDate);


	}
	@Test
	public void testRedo() {
		
		assertEquals(arrList.size(),1);
		t1.execute("Task 1");
		assertEquals(arrList.size(),0);
		t1.undo();
		assertEquals(arrList.size(),1);
		t1.redo();
		assertEquals(arrList.size(),0);

	}
}